<?php

//

require "database.php";

$order_on   =trim((string)$_GET["orderon"]);

$_result_   =trim((string)$_GET['result']);

$issue      =$_GET["issue"];

$orderid=(int)$_GET["id"];

$__________poin=(int)$_GET["poin"];

$tree=file_get_contents("tree.json");
$tree=json_decode($tree,1);

$_copyorder=file_get_contents("copyorder.json");
$_copyorder=json_decode($_copyorder,1);

$__issue__=file_get_contents("issue.json");
$__issue__=json_decode($__issue__,1);
$__issue____=$__issue__[count($__issue__)-1];

if($__________poin){
    $__________poin+=1;
}

if($_result_){
    $s=stristr($_result_,"-");
    if($s){
        $_result_="no";
    }else{
        $_result_="yes";
    }
}

for ($a = 0; $a < count($tree); $a++) {
    for ($b = 0; $b < count($tree[$a]["tree"]); $b++) {
        if(!empty($tree[$a]["tree"][$b]["order"])){
            for ($c = 0; $c < count($tree[$a]["tree"][$b]["order"]); $c++) {
                for ($i = 0; $i < count($_copyorder); $i++) {
                    if($tree[$a]["tree"][$b]["order"][$c]["id"]==$orderid){
                        if($order_on){
                            // $tree[$a]["tree"][$b]["order"][$c]["order_no"]=$order_on;
                            if($_copyorder[$i]["id"]==$tree[$a]["tree"][$b]["order"][$c]["id"] && $_copyorder[$i]["issue"]==$tree[$a]["tree"][$b]["order"][$c]["issue"]){
                                $_copyorder[$i]["order_no"]=$order_on;
                                break;
                            }
                        }
                    }
                    if($_result_ && $tree[$a]["tree"][$b]["order"][$c]["order_no"]==$order_on){
                        // $tree[$a]["tree"][$b]["order"][$c]["result"]=$_result_;
                        if($_copyorder[$i]["id"]==$tree[$a]["tree"][$b]["order"][$c]["id"] && $_copyorder[$i]["issue"]==$tree[$a]["tree"][$b]["order"][$c]["issue"]){
                            $_copyorder[$i]["result"]=$_result_;
                            break;
                        }
                    }
                    if($tree[$a]["tree"][$b]["order"][$c]["id"]==$orderid && $__________poin){
                        // $tree[$a]["tree"][$b]["order"][$c]["poin"]=$__________poin;
                        if($_copyorder[$i]["id"]==$tree[$a]["tree"][$b]["order"][$c]["id"] && $_copyorder[$i]["issue"]==$tree[$a]["tree"][$b]["order"][$c]["issue"]){
                            $_copyorder[$i]["poin"]=$__________poin;
                            break;
                        }
                    }
                }
            }
        }
    }
}





$f=file_put_contents("copyorder.json",json_encode($_copyorder,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE));



if($f){
    return json([
        "code"=>200,"msg"=>"success"
    ]);
}else{
    return json([
        "code"=>-1,"msg"=>"fuil"
    ]);
}

